﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace WinFormsApp1
{
    /// <summary>
    /// 泛型接口，定义基本的数据访问操作
    /// </summary>
    /// <typeparam name="TEntity">实体类型</typeparam>
    public interface IBaseRepository<TEntity> where TEntity : class, new()
    {
        /// <summary>
        /// 异步创建实体
        /// </summary>
        /// <param name="entity">要创建的实体</param>
        /// <returns>创建是否成功</returns>
        Task<bool> CreateAsync(TEntity entity);

        /// <summary>
        /// 异步根据ID删除实体
        /// </summary>
        /// <param name="id">要删除的实体的ID</param>
        /// <returns>删除是否成功</returns>
        Task<bool> DeleteAsync(int id);

        /// <summary>
        /// 异步编辑实体
        /// </summary>
        /// <param name="entity">要编辑的实体</param>
        /// <returns>编辑是否成功</returns>
        Task<bool> EditAsync(TEntity entity);

        /// <summary>
        /// 异步根据ID查找实体
        /// </summary>
        /// <param name="id">要查找的实体的ID</param>
        /// <returns>查找到的实体</returns>
        Task<TEntity> FindAsync(int id);

        /// <summary>
        /// 异步根据条件查找实体
        /// </summary>
        /// <param name="func">查询条件</param>
        /// <returns>查找到的实体</returns>
        Task<TEntity> FindAsync(Expression<Func<TEntity, bool>> func);

        /// <summary>
        /// 异步查询全部数据
        /// </summary>
        /// <returns>查询到的实体列表</returns>
        Task<List<TEntity>> QueryAsync();

        /// <summary>
        /// 异步根据条件查询数据
        /// </summary>
        /// <param name="func">查询条件</param>
        /// <returns>查询到的实体列表</returns>
        Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> func);

        /// <summary>
        /// 异步分页查询数据
        /// </summary>
        /// <param name="page">页码</param>
        /// <param name="size">每页大小</param>
        /// <param name="total">总记录数</param>
        /// <returns>查询到的实体列表</returns>
        Task<List<TEntity>> QueryAsync(int page, int size, RefAsync<int> total);

        /// <summary>
        /// 异步根据条件分页查询数据
        /// </summary>
        /// <param name="func">查询条件</param>
        /// <param name="page">页码</param>
        /// <param name="size">每页大小</param>
        /// <param name="total">总记录数</param>
        /// <returns>查询到的实体列表</returns>
        Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> func, int page, int size, RefAsync<int> total);
    }
}
